package com.china.produce.thread;

import java.util.ArrayList;
import java.util.concurrent.*;

/**
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2022/7/21
 */
public class ShutDown {

    public static void main(String[] args) {


        ScheduledExecutorService service = Executors.newScheduledThreadPool(4);

        ArrayList<Future<String>> futures = new ArrayList<>();

        Future<String> future = service.submit(new Task());

        Future<String> future2 = service.submit(new LongTask());

        Future<String> future3 = service.submit(new LongTask());

        futures.add(future);

        futures.add(future2);

        futures.add(future3);

        service.shutdown();

        try {
            if (service.awaitTermination(30, TimeUnit.SECONDS)) {
//                for (int i = 0; i < futures.size(); i++) {
//                    String s = futures.get(i).get();
//                    System.out.println(s);
//                }
                System.out.println(Thread.currentThread().getName() + " 线程池关闭");
            }
        }catch (InterruptedException e) {
            Thread.currentThread().interrupt();

            e.printStackTrace();
        }

        System.out.println("6666");
    }
}
